/*
NewUTTransactionController
Version 1.0
Description: Controller Class for Visual Force page: NewUTTransaction
Author: Pratibh Prakash
Created Date: 9 Feb-2009
*/
public class NewUTTransactionController {

    //private String Client_Name;
   // private Integer Amount;
    //private String curency;
   // private String DealingTerms;
   // private Integer No_of_Units;
   // private String Remarks;
   // private String SpecialInstruction;
   // private String SwitchingFee;
   // private String SwitchingFeeRemark;
   // private String TransactionType;
   // private String UTFundName;
    public UT_Transactions__c objUT_Transaction{get;private set;}
    public UT_Transactions__c objUT_Trans{get;private set;}
    public String value;
    private UT_Transactions__c record;
    Integer flag=0;
   
    private UT_Fund__c objUTFund;
    public NewUTTransactionController(ApexPages.StandardController controller) {
		
		//objUT_Transaction = (UT_Transactions__c)controller.getRecord();
		//objUT_Trans = [select Amount__c, Currency__c, UT_Client__c, Dealing_Terms__c, No_of_Units__c, 
						//Remarks__c, Special_Instruction__c, Switching_Fee__c, Switching_Fee_Remark__c,
						//Transaction_Type__c, UT_Fund_Name__c from UT_Transactions__c where id =: objUT_Trans.Id];
		if(objUT_Trans==null){
			objUT_Trans = new UT_Transactions__c();
			
		}
		if(objUT_Transaction==null){
			objUT_Transaction = new UT_Transactions__c();
		}
		
    	
    }
    
    /*
    save()
    Description: Method saves record for UT_Transactions__c.
    */
    public PageReference save(){
    	
    	
    	PageReference UTPage;
    	UT_Fund__c objUTFund =[select Currency__c, Cut_off_Time__c from UT_Fund__c where id =: objUT_Trans.UT_Fund_Name__c];
    	record = new UT_Transactions__c(Amount__c = objUT_Trans.Amount__c , Transaction_Date__c = objUT_Trans.Transaction_Date__c, 
    									Currency__c = objUTFund.Currency__c, UT_Client__c = objUT_Trans.UT_Client__c, 
    									Dealing_Terms__c = objUT_Trans.Dealing_Terms__c, No_of_Units__c= objUT_Trans.No_of_Units__c, 
    									Remarks__c = objUT_Trans.Remarks__c, Special_Instruction__c = objUT_Trans.Special_Instruction__c, 
    									Switching_Fee__c = objUT_Trans.Switching_Fee__c, 
    									Switching_Fee_Remark__c = objUT_Trans.Switching_Fee_Remark__c, 
    									Transaction_Type__c = objUT_Trans.Transaction_Type__c, 
    									UT_Fund_Name__c = objUT_Trans.UT_Fund_Name__c);
    	if(objUT_Trans.Transaction_Type__c=='Purchase(Switch In)'){
    		
    		objUT_Transaction.Transaction_Type__c = 'Redemption(Switch Out)';
    		
        	return Page.UT_Transaction_2;
    	}
    	if(objUT_Trans.Transaction_Type__c=='Redemption(Switch Out)'){
    		
    		objUT_Transaction.Transaction_Type__c = 'Purchase(Switch In)';
    		
        	return Page.UT_Transaction_2;
    	}
    	else{
    		
    		if(objUTFund.Cut_off_Time__c < datetime.now()&& flag==0){
    			ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'U r getting warned'+flag);
            	ApexPages.addMessage(myMsg);
            	UTPage =null;    			
        		flag +=1;
        	}
        	else{
        		UTPage = new PageReference('/a06/o');
        		UTPage.setRedirect(true);
        		insert(record);
        	}
        	
    		return UTPage;
    	}
    	
    }
    
    public PageReference saveTwo(){
    	UT_Fund__c objUTFund =[select Currency__c from UT_Fund__c where id =: objUT_Transaction.UT_Fund_Name__c];
    	UT_Transactions__c recordTwo = new UT_Transactions__c(Amount__c = objUT_Transaction.Amount__c , 
    														    Transaction_Date__c = objUT_Transaction.Transaction_Date__c,
    														    Currency__c = objUTFund.Currency__c, 
    															UT_Client__c = objUT_Transaction.UT_Client__c, 
    															Dealing_Terms__c = objUT_Transaction.Dealing_Terms__c, 
    															No_of_Units__c= objUT_Transaction.No_of_Units__c, 
    															Remarks__c = objUT_Transaction.Remarks__c, 
    															Special_Instruction__c = objUT_Transaction.Special_Instruction__c, 
    															Switching_Fee__c = objUT_Transaction.Switching_Fee__c, 
    															Switching_Fee_Remark__c = objUT_Transaction.Switching_Fee_Remark__c, 
    															Transaction_Type__c = objUT_Transaction.Transaction_Type__c, 
    															UT_Fund_Name__c = objUT_Transaction.UT_Fund_Name__c);
    	insert(record);
    	insert(recordTwo);
    	PageReference UTPage = new PageReference('/a06/o');
        UTPage.setRedirect(true);
        return UTPage;
    }
   
    
    
  
   
}